import { createRouter, createWebHistory } from 'vue-router'

import Home from '@/views/Home/Home.vue'
import questions from '@/views/questions/dayi.vue'
import manage from '../views/manage/manage.vue'
import wenzhen from '@/views/Consultationsystem/Consult.vue'
import advice from '@/views/advice/Advice.vue'
import message from '@/views/message/ling.vue'
import Consultation from '@/views/Consultation/Consultation.vue'
import cha from '@/views/Cha/cha.vue'
import qian from '@/views/wallet/wallet.vue'
import bang from '@/views/binding/Binding.vue'
import deng from '@/views/deng/deng.vue'
import Determinebinding from '@/views/identitycard/shen.vue'
import login from '@/views/Login/login.vue'
import ConsultationList from '../views/ConsultationList/index.vue'
import information from '../views/information/index.vue'
import liao from '../views/chatroom/index.vue'
import system from '../views/System/index.vue'
import report from '../views/report/index.vue'
import lian from '../views/contact/index.vue'
import Withdrawalrecord from '../views/record/index.vue'
import Identitycard from '../views/Identitycard/shen.vue'
import bangyin from '../views/bank/index.vue'
import chatroom from '@/until/chatroom.vue'
import loading from '@/until/loading/loading.vue'
import wallitmation from '@/views/wallitmation/wallitmation.vue'
import record from '../until/record.vue'
import accept from '../views/Accept/index.vue'
import withdraw from '@/views/Withdraw/withdraw.vue'
import purse from '@/views/Purse/purse.vue'
import mylist from '../views/Mylist/mylist/index.vue'

import MYlist from '../until/Mylist.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
        path:'/',
        name:"loading",
        component:loading
    } 
    // 主页面
    ,
    {
      path: '/home',
      name: 'home',
      component: Home
    },
    
    {
      path: '/questions',
      name: 'questions',
      component: questions
    },
    // 问诊的消息页
    {
      path: '/manage',
      name: 'manage',
      component: manage
    },
    // 钱包页
    {
      path:'/wallitmation',
      name:"wallitmation",
      component:wallitmation
    },
    // 问诊页面
    {
      path: '/wenzhen',
      name: 'wenzhen',
      component: wenzhen
    },
    {
      path: '/ConsultationList',
      name: 'ConsultationList',
      component: ConsultationList
    },
    // 信息页
    {
      path: '/information',
      name: 'information',
      component: information
    },
    // 聊天室
    {
      path:"/chatroom",
      name:"chatroom",
      component:chatroom
    },
    //聊天用户详情
    {
      path:'/mylist/:id',
      name:'mylist',
      component:mylist
    },
    {
      path:'/Mylist/:id',
      name:'Mylist',
      component:MYlist
    },
    {
      path: '/liao',
      name: 'liao',
      component: liao
    },
    // 系统消息页面
    {
      path: '/system',
      name: 'system',
      component: system
    },
  
    {
      path: '/report',
      name: 'report',
      component: report
    },
    
    {
      path: '/lian',
      name: 'lian',
      component: lian
    },
    {
      path: '/jilu',
      name: 'jilu',
      component: advice
    },
    
    {
      path: '/bang',
      name: 'bang',
      component: bang
    },
    {
      path:'/identitycard',
      name:'identitycard',
      component:Identitycard
    },
    {
      path: '/bangyin',
      name: 'bangyin',
      component: bangyin
    },
    // 个人信息
    {
      path:"/personal",
      name:"personal",
      component:()=>import('../views/manage/personal/personal.vue')
    },
    // 管理问诊
    {
      path:"/hisconsultation",
      name:"hisconsultation",
      component:()=>import('../views/manage/glbox/hisconsultation.vue')
    },
    // 管理钱包
    {
      path:"/mywallet",
      name:"mywallet",
      component:()=>import('../views/manage/glbox/mywallet.vue')
    },
    // 管理建议
    {
      path:"/Recommendations",
      name:"Recommendations",
      component:()=>import('../views/manage/glbox/Recomme.vue')
    },
    // 管理设置回复
    {
      path:"/reply",
      name:"reply",
      component:()=>import('../views/manage/glbox/reply.vue')
    },
    // 身份信息
    {
      path:"/binding",
      name:"binding",
      component:()=>import('../until/binding.vue')
    },
    // 提现页面
    {
      path:"/Cash",
      name:"Cash",
      component:()=>import('../until/Cash.vue')
    },
    // 提现记录
    {
      path:"/history",
      name:"history",
      component:()=>import('../until/history.vue')
    },
    //礼物页面
    {
      path:'/accept',
      name:'accept',
      component:accept
    },
    {
      path: '/jixun',
      name: 'jixun',
      component: advice
    },
     {
      path: '/message',
      name: 'message',
      component: message
    },
    {
      path:'/Consultation',
      name:'Consultation',
      component:Consultation
    },
    {
      path:"/cha",
      name:'cha',
      component:cha
    },
    {
      path:'/qian',
      name:'qian',
      component:qian
    },
    {
      path:'/bang',
      name:'bang',
      component:bang
    },
    {
      path:'/deng',
      name:'deng',
      component:deng
    },
    // 登录页面
    {
      path: '/login',
      name: 'login',
      component:login
    },
    {
      path: '/bang',
      name: 'bang',
      component: bang
    },
    //跳转详情
    {
      path:'/record/:id',
      name:'record',
      component:record
    },
    // 评价详情页面
    {
      path:"/appraise",
      name:"appraise",
      component:()=>import('../until/appraise.vue')
    },
    // 判断绑定
    {
      path:'/Determinebinding',
      name:'Determinebinding',
      component:Determinebinding
    },
    //提现新页面
    {
      path:"/withdraw",
      name:"withdraw",
      component:withdraw
    },
    {
      path:"/purse",
      name:"purse",
      component:purse
    },
    {
      path:'/Withdrawalrecord',
      name:'Withdrawalrecord',
      component:Withdrawalrecord
    }
  ]
})

router.beforeEach((to,form,next)=>
{
    if(to.path == '/login')
    {
      next()
    }
    else
    {
      let token = localStorage.getItem('token')
      if(token)
      {
        next()
      }
      else
      {
        next('/login')
      }
    }
  
})

export default router
